package cn.tuling.account.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

public class MybatisGeneratorUtil {
    public static void main(String[] args) {
        FastAutoGenerator.create(new DataSourceConfig.Builder("jdbc:mysql://81.70.2.227:3306/seata", "root", "root"))
                .globalConfig(builder -> {
                    builder.author("wuyanzhao") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("G:\\mygitee\\learn-springcloud-alibaba\\seata\\seata-test\\seata-account\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("cn.tuling.account") // 设置父包名
                            .entity("po")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "G:\\mygitee\\learn-springcloud-alibaba\\seata\\seata-test\\seata-account\\src\\main\\resources\\mappers")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("seata_account") // 设置需要生成的表名
                            // 设置过滤表前缀
                            .addTablePrefix("seata_")
                            .entityBuilder().enableLombok()
                            .controllerBuilder().enableRestStyle()
                            .serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImpl")
                            .mapperBuilder().enableMapperAnnotation().formatMapperFileName("%sMapper");
                })
                .execute();
    }
}
